package com.ruoyi.data.controller;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.data.domain.*;
import com.ruoyi.data.service.IDataService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/did/data")
public class DataController {

    @Resource
    private IDataService service;

    @PostMapping("/upload")
    public AjaxResult uploadData(@RequestBody DataInfo data) {
        service.uploadData(data);
        return AjaxResult.success("数据上传成功");
    }

    @GetMapping("/list")
    public AjaxResult listAllData() {
        List<DataInfo> list = service.listAllData();
        return AjaxResult.success(list);
    }

    @PostMapping("/request")
    public AjaxResult requestAccess(@RequestBody DataAccessRequest request) {
        service.submitAccessRequest(request);
        return AjaxResult.success("访问请求已提交");
    }

    @PutMapping("/approve/{id}")
    public AjaxResult approveRequest(@PathVariable("id") Long id) {
        service.approveRequest(id);
        return AjaxResult.success("访问请求已批准");
    }

    @PutMapping("/reject/{id}")
    public AjaxResult rejectRequest(@PathVariable("id") Long id) {
        service.rejectRequest(id);
        return AjaxResult.success("访问请求已拒绝");
    }

    @PostMapping("/grant")
    public AjaxResult grantPermission(@RequestBody DataPermission permission) {
        service.grantPermission(permission);
        return AjaxResult.success("权限已授予");
    }

    @DeleteMapping("/revoke/{id}")
    public AjaxResult revokePermission(@PathVariable("id") Long id) {
        service.revokePermission(id);
        return AjaxResult.success("权限已撤销");
    }
}
